package com.kania.simpleemail.setup;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.kania.simpleemail.R;

public class ProviderListActivity extends Activity {
	private ListView listProviders;
	private String[] sProviders = {"Gmail", "Yahoo", "Naver"};
	private ArrayList<String> alProviders = new ArrayList<String>();
	static final int REQUEST_CODE = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_provider_list);
		listProviders = (ListView)findViewById(R.id.listProviders);
		listProviders.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> a, View v, int position, long id) {
				String sProvider = sProviders[position];
				if (sProviders[0].equalsIgnoreCase(sProvider)) {
					//Intent intentLogin = new Intent(ProviderListActivity.this, LoginActivity.class);
					Intent intentLogin = new Intent(ProviderListActivity.this, LoginActivityEx.class);
					intentLogin.putExtra("provider", sProvider);
					startActivityForResult(intentLogin, REQUEST_CODE);
				} else {
					Toast.makeText(ProviderListActivity.this, sProvider + " is not available yet.", Toast.LENGTH_SHORT).show();
				}
			}
		});
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		alProviders.clear();
		for (int i = 0; i < sProviders.length; i++) {
			alProviders.add(sProviders[i]);
		}
		listProviders.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, alProviders));
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		
		switch(requestCode){
		case REQUEST_CODE:
			if(resultCode == RESULT_OK){
				finish();
			}
			break;
		}
	}
	
}


